package com.ld.admin.util.daliySentence.impl;

import org.apache.commons.lang.math.RandomUtils;
import org.jsoup.nodes.Document;
import org.jsoup.select.Elements;

import com.ld.admin.util.daliySentence.DaliySentence;
import com.ld.admin.util.daliySentence.DaliySentenceUtil;
import com.ld.admin.util.daliySentence.model.DaliySentenceModel;
import com.ld.shieldsb.common.core.util.JsoupUtil;

/**
 * 
 * one一个
 * 
 * @author <a href="mailto:donggongai@126.com" target="_blank">吕凯</a>
 * @date 2020年1月8日 下午2:12:23
 *
 */
public class DaliySentenceOne implements DaliySentence {
    // 未使用的 https://www.dailyenglishquote.com
    public static final String KEY = "one";
    public static final String NAME = "ONE·一个";
    public static final String URL = "http://wufazhuce.com/"; // one一个的网址
    public static final String LINK_URL = "http://wufazhuce.com";
    public static final String DESCRIPTION = "每天只为你准备一张图片、一篇文字和一个问答。韩寒主编和监制 原《独唱团》主创成员共同制作"; // 描述

    @Override
    public DaliySentenceModel getSentence() {
        DaliySentenceModel model = null;
        String htmlContent = null;
        Document document = JsoupUtil.getRemoteURLDocument(getURL(), null);
        if (document != null) {
            model = new DaliySentenceModel();
            Elements contentCs = document.select("div.fp-one-cita");
            Elements images = document.select(".fp-one-imagen"); // 图片
            int random = RandomUtils.nextInt(20) % contentCs.size();

            String picUrl = images.get(random).attr("src");
            String content = contentCs.get(random).select("a").text();

            htmlContent = "<img src=\"" + picUrl + "\" width='270' >" + "<br/>"; // height='180'
            htmlContent += content + DaliySentenceUtil.getLinkedStr(getURL(), getName());

            model.setHtmlContent(htmlContent);
            model.setContent(content);
//            model.setOrigin("");
            model.setPicUrl(picUrl); // 图片
            model.setBaseInfo(getBaseInfo());
        }
        return model;
    }

    @Override
    public String getKey() {
        return KEY;
    }

    @Override
    public String getName() {
        return NAME;
    }

    @Override
    public String getURL() {
        return URL;
    }

    @Override
    public String getLinkURL() {
        return LINK_URL;
    }

    @Override
    public String getDescription() {
        return DESCRIPTION;
    }

}
